package com.assembly.system.controller;


import com.assembly.entities.SystemUser;
import com.assembly.system.req.UserREQ;
import com.assembly.system.req.UserUpdatePasswordREQ;
import com.assembly.system.service.IUserService;
import com.assembly.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 平台用户信息表 前端控制器
 * </p>
 *
 * @author 丽人平台-www.assembly.com
 * @since 2021-03-29
 */
@Api("平台用户信管理，对用户的增删改查")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;


    @ApiOperation("注册账号")
    @PostMapping
    public Result userRegister(@RequestBody SystemUser user){

        return   userService.userRegister(user);
    }

    /***
     * 用户列表查询
     * @param userREQ
     * @return
     */
    @ApiOperation("用户列表查询 ")
    @PostMapping("search")
    public Result findListByUser(UserREQ userREQ){

        return Result.ok( userService.findListByUser(userREQ));

    }

    /**
     * 根据 ID查询用户信息
     * @param id
     * @return
     */
    @ApiOperation("根据 ID查询用户信息 ")
    @ApiImplicitParam(name = "id", value = "用户id", required = true)
    @GetMapping("{id}")
    public Result  findUserById(@PathVariable("id") String id){

        return  Result.ok(userService.findUserById(id));

    }

    /***
     * 根据账号 查询用户信息
     * @param account
     * @return
     */
    @ApiOperation("根据账号 查询用户信息")

    @ApiImplicitParams({@ApiImplicitParam(name = "account", value = "用户名", required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "type", value = "账号的平台类型", required = true,dataType ="int",paramType = "query")}
    )
    @GetMapping("account/{account}/{type}")
    public Result  findUserByAccount(@PathVariable("account")  String account,@PathVariable("type") int type){

        return  Result.ok(userService.findUserByAccount(account,type));
    }


    /***
     * 修改密码
     * @param userUpdatePasswordREQ
     */
    @ApiOperation("修改密码")
    @PostMapping("updatePws")
    public Result  updatePassWord(@RequestBody UserUpdatePasswordREQ userUpdatePasswordREQ){

        return  Result.ok(userService.updatePassWord(userUpdatePasswordREQ));
    }

    /***
     * 校验用户名是否存在
     * @param account
     * @return
     */

    @ApiOperation("校验平台用户名是否存在")
    @PostMapping("platform/{account}")
    public Result  checkPlatformAccount(@PathVariable("account") String account){

        return  Result.ok(userService.checkAccount(account,1));

    }

    @ApiOperation("校验B端用户名是否存在")
    @PostMapping("b/{account}")
    public Result  checkBAccount(@PathVariable("account") String account){

        return  Result.ok(userService.checkAccount(account,2));
    }


    @ApiOperation("校验C端用户名是否存在")
    @PostMapping("c/{account}")
    public Result  checkCAccount(@PathVariable("account") String account){

        return  Result.ok(userService.checkAccount(account,3));
    }


    /***
     * 校验用手机是否存在
     * @param mobile
     * @return
     */
    @ApiOperation("校验C端手机号是否存在")
    @PostMapping("c/{mobile}")
    public Result  checkPlatformMobile(@PathVariable("mobile") String mobile){

        return  Result.ok(userService.checkAccount(mobile,3));
    }


    /***
     * 校验用手机是否存在
     * @param mobile
     * @return
     */
    @ApiOperation("校验B端手机号是否存在")
    @PostMapping("b/{mobile}")
    public Result  checkBMobile(@PathVariable("mobile") String mobile){

        return  Result.ok(userService.checkAccount(mobile,2));
    }


    /***
     * 校验用手机是否存在
     * @param mobile
     * @return
     */
    @ApiOperation("校验平台端手机号是否存在")
    @PostMapping("platform/{mobile}")
    public Result  checkMobile(@PathVariable("mobile") String mobile){

        return  Result.ok(userService.checkAccount(mobile,1));
    }


    /***
     * 校验平台端身份证是否存在
     * @param identity
     * @return
     */
    @ApiOperation("校验平台端身份证是否存在")
    @PostMapping("platform/{identity}")
    public Result  checkPlatformIdentity(@PathVariable("identity") String identity){

        return  Result.ok(userService.checkIdentity(identity,1));
    }
    /***
     * 校验B端身份证是否存在
     * @param identity
     * @return
     */
    @ApiOperation("校验B端身份证是否存在")
    @PostMapping("b/{identity}")
    public Result  checkBIdentity(@PathVariable("identity") String identity){

        return  Result.ok(userService.checkIdentity(identity,2));
    }

    /***
     * 校验c端身份证是否存在
     * @param identity
     * @return
     */
    @ApiOperation("校验B端身份证是否存在")
    @PostMapping("c/{identity}")
    public Result  checkCIdentity(@PathVariable("identity") String identity){

        return  Result.ok(userService.checkIdentity(identity,2));
    }


    /***
     * 修改用户信息
     * @param
     * @return
     */
    @ApiOperation("校验B端身份证是否存在")
    @PutMapping
    public  Result updateUser(@RequestBody SystemUser user){
        user.setUpdateDate(new Date());
        userService.updateById(user);
       return Result.ok();
    }

}
